<?php

namespace App\Common\Traits;


trait ScopeQuery
{
    public function scopeRecent($query)
    {
        return $query->orderBy('updated_at', 'desc');
    }

    public function scopeName($query, $name)
    {
        return $query->where('name', 'like', '%' . $name . '%');
    }

    public function scopeProjectName($query, $projectname)
    {
        return $query->where('project_name', 'like', '%' . $projectname . '%');
    }

    public function scopeCode($query, $code)
    {
        return $query->where('code', 'like', '%' . $code . '%');
    }

    public function scopeActive($query)
    {
        return $query->where('active', 1);
    }

    public function scopeType($query, $type)
    {
        return $query->where('type', $type);
    }

    public function scopeStatus($query, $status)
    {
        return $query->where('status', $status);
    }

    public function scopeLike($query, $key, $value)
    {
        return $query->where($key, 'like', '%' . $value . '%');
    }

    public function scopeDisplay($query)
    {
        return $query->where('display', true);
    }

    public function scopeRole($query, $role)
    {
        return $query->where('role', $role);
    }
}